
***********************************************************************************************************************
**** Table 3. ITT Effects in Comparison to Basic Treatment ************************************************************
***********************************************************************************************************************

use "$data/Non_payment_dataset_ready.dta" , clear

log using "$filepath/output_logs/table 3", replace

*********************************
**** Initial month (October) ****
*********************************

local controls "itt2 itt3 premeaninvoicew presumpaymentratiow preage_of_accountw preclosingbalancew prepaidcounttotal interviewerdummy* datedummy* schemedummynew*"

* Extensive Margin *
probit paidcount `controls' if t==14 , rob
margins, dydx(itt2 itt3) post

*Intensive Margin*
reg lnpayment `controls' if t==14, rob

*TWO PM estimation - *
* ssc install twopm  // twopm is a user written command and needs to be installed
preserve 
keep if t==14
capture program drop Ey_boot
program define Ey_boot, eclass
twopm payment itt2 itt3 premeaninvoicew presumpaymentratiow preage_of_accountw preclosingbalancew prepaidcounttotal interviewerdummy* datedummy* schemedummynew*, firstpart(probit) secondpart(regress, log) vce(cluster customer)
margins, dydx(itt2 itt3) predict(duan) nose post
end
bootstrap _b, seed(3125) reps(1000): Ey_boot
estimates store W 
restore

* IHS payment *
reg asinhpayment `controls' if t==14,  vce(cluster customer)

* Comparison means *
sum  paidcount lnpayment payment asinhpayment if t==14 & itt==0 

*************************************
**** Medium term (November-June) ****
*************************************

local controls "itt2 itt3 i.t premeaninvoicew presumpaymentratiow preage_of_accountw preclosingbalancew prepaidcounttotal interviewerdummy* datedummy* schemedummynew*"

*midterm *
probit paidcount `controls' if t>=15 & t<=22, vce(cluster customer)
margins, dydx(itt2 itt3) post

*Intensive Margin*
reg lnpayment `controls' if t>=15 & t<=22, vce(cluster customer)

*TWO PM*
preserve 
keep if t>=15 & t<=22
capture program drop Ey_boot
program define Ey_boot, eclass
twopm payment itt2 itt3 i.t premeaninvoicew presumpaymentratiow preage_of_accountw preclosingbalancew prepaidcounttotal interviewerdummy* datedummy* schemedummynew* , firstpart(probit) secondpart(regress, log) vce(cluster customer)
margins, dydx(itt2 itt3) predict(duan) nose post
end
bootstrap _b, seed(3125) reps(1000): Ey_boot
restore

reg asinhpayment `controls' if t>=15 & t<=22, vce(cluster customer)

sum  paidcount lnpayment payment asinhpayment if t>=15 & t<=22 & itt==0 // comparison values

log close
